#include "httprequest.h"

HttpRequest::HttpRequest(QObject *parent) :
    QObject(parent)
{
    manager = new QNetworkAccessManager(this);
    connect(manager,SIGNAL(finished(QNetworkReply*)),this, SLOT(excuteFinish(QNetworkReply*)));
}

QNetworkReply* HttpRequest::get(QUrl url){

    QNetworkReply *reply = manager->get(QNetworkRequest(url));

    QEventLoop eventLoop;
    connect(manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
    eventLoop.exec();       //block until finish

    return reply;
}

void HttpRequest::excuteFinish(QNetworkReply* reply){
    emit requestFinish(reply);
}

HttpRequest::~HttpRequest(){
    delete manager;
}
